A Few More Git Tips & Tricks

In a recent post I briefly covered a few of the more common tasks you encounter in a typical Git workflow.

 

Today I’d like to highlight a few more tidbits of Git, perhaps a bit less straightforward but essential when you’re in a pinch. They may be a little confusing if you don’t understand the Git flow, but if you understand the basics well, you should be able to put these techniques to good use, and find your way out of a few sticky situations.

 

1. Merge individual files. Pulling in specific files from one branch to another can be a huge help when you don’t want to merge everything. Sometimes you don’t want overlap in certain parts of your branches, and it can be tricky to sort out. Look no further — these techniques make it simple to bring in just the changes you require.

 

2. Undo a single commit. “Whoops” is a common interjection, but recovering from that moment is what Git excels at. A few short commands will have you back where you started.

 

3. Fix a “corrupt loose object.” Grrr. This one’s a nuisance. It happens when Git’s internal storage gets messed up, and if you’re not careful it can be a giant pain to fix. Or it can be simple, if you follow the instructions in the link. Just remember to commit early and commit often, boys and girls! You will lose uncommitted changes on this one.

 

Truth be told, “commit early and commit often” is a good mantra to employ at all times with version control of any kind — after all, that’s a large part of what it’s for! Keep the purpose of your tools in mind as you use them and you’re off to a good start.

 

Best of luck in your endeavors!